package com.bitsemart.dialogos;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

import com.bitsemart.R;

import java.util.ArrayList;

/**
 * Created by Adrian on 15/05/2015.
 */
public class FilterDialogFragment extends DialogFragment {
    ArrayList mSelectedItems;
    private EditText mEditTextDeveloper;
    private EditText mEditTextGenre;
    private IFilterDialogFragment myIFDF;
    public static String developerFilter;
    public static String genreFilter;

    @Override
    public Dialog onCreateDialog(final Bundle savedInstanceState) {
        super.onCreateDialog(savedInstanceState);
        mSelectedItems = new ArrayList();  // Where we track the selected items
        // Use the Builder class for convenient dialog construction
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

        builder.setTitle(R.string.action_filter);
        LayoutInflater inflater = getActivity().getLayoutInflater();
        builder.setView(inflater.inflate(R.layout.filter_dialog, null))
                .setPositiveButton(R.string.apply, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        mEditTextDeveloper = (EditText) getDialog().findViewById(R.id.developer_filter);
                        mEditTextGenre = (EditText) getDialog().findViewById(R.id.genre_filter);
                        //Aqui los datos los saca bien
                        developerFilter = mEditTextDeveloper.getText().toString();
                        genreFilter = mEditTextGenre.getText().toString();
                        myIFDF.onDialogPositiveClick(FilterDialogFragment.this);

                    }
                })
                .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        myIFDF.onDialogNegativeClick(FilterDialogFragment.this);
                    }
                });
        // Create the AlertDialog object and return it
        return builder.create();
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        myIFDF = (IFilterDialogFragment) activity;
    }
}
